package com.deepclassifieds.daas.api.builder;

import com.deepclassifieds.daas.api.xsd.Column;
import com.deepclassifieds.daas.api.xsd.Columns;
import com.deepclassifieds.daas.api.xsd.Record;
import com.deepclassifieds.daas.common.Builder;
import com.deepclassifieds.daas.common.Name;
import com.deepclassifieds.daas.common.Reject;

public class RecordBuilder implements Builder<Record> {
	
	private final Record record;
	
	public RecordBuilder() {
		this.record = new Record();
		this.record.setColumns(new Columns());
	}
	
	@Override
	public Record build() {
		return record;
	}

	public Column createAndAddColumn(Name columnName, String columnValue) {
		Reject.ifNull(columnName);
		Column column = new Column();
		column.setName(columnName.toString());	
		column.setValue(columnValue);
		column.setNull(columnValue == null);
		record.getColumns().getColumn().add(column);
		return column;
	}
	
	public void addColumns(Columns columns) {
		Reject.ifNull(columns);
		record.getColumns().getColumn().addAll(columns.getColumn());
	}

}
